﻿using System.Web.Mvc;
using Journal.Front.Presentation.FilterAttributes;
using Journal.Front.Presentation.Models.AccountModels;
using Journal.Front.Presentation.Models.UserModels;
using Journal.Front.Presentation.PresentationServicesInterfaces;

namespace Journal.Front.Presentation.Controllers
{
    public class UserController : Controller
    {
        private readonly IUserPresentationService userPresentationService;

        public UserController(IUserPresentationService userPresentationService)
        {
            this.userPresentationService = userPresentationService;
        }

        public ActionResult GetUser()
        {
            return View("../Slicing/UserPage");
        }

        [HttpGet]
        public ActionResult GetUser(int id)
        {
            UserEditModel model = userPresentationService.GetUserEditModel(id);
            return View("Edit", model);
        }

        [HttpPost]
        public ActionResult SaveUser(UserEditModel model)
        {
            if(ModelState.IsValid)
            {
                userPresentationService.Save(model);
                return RedirectToAction("Index", "StudyRoom");
            }

            return View("Edit", model);
        }
    }
}